package Pet.Management.repository;

import Pet.Management.domain.entity.TaskNode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TaskNodeRepository extends JpaRepository<TaskNode, Long> {
    List<TaskNode> findByOrderIdOrderByNodeOrder(Long orderId);
    
    TaskNode findByOrderIdAndNodeOrder(Long orderId, Integer nodeOrder);
    
    @Query("SELECT COUNT(t) FROM TaskNode t WHERE t.orderId = :orderId AND (t.status = 0 OR t.status IS NULL)")
    Integer countUnconfirmedNodes(@Param("orderId") Long orderId);
    
    @Query("SELECT t FROM TaskNode t WHERE t.orderId = :orderId AND t.status = 0 ORDER BY t.nodeOrder ASC")
    List<TaskNode> findPendingNodesByOrderId(@Param("orderId") Long orderId);
    
    void deleteByOrderId(Long orderId);
} 